<%@ page import="com.uni.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>闲优购-</title>

    <link rel="icon" href="img/weblogo.png" >
    <link rel="stylesheet" type="text/css" href="bootstrap-5.1.3-dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link rel="stylesheet" type="text/css" href="css/ycc.css"/>
    <script type="text/javascript" src="js/jquery-3.6.0-min.js"></script>
    <script type="text/javascript" src="bootstrap-5.1.3-dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/card_user_buy_record.js"></script>
<body>
<div style="margin-inline: auto">
    <h5>当前位置:站点管理>>添加新用户</h5>
</div>

<div style="float: right;">

</div>

<form id="form-insert-user" class="text-center">
    <div class="row">
        <ul style="list-style-type: none;">
            <li class="row p-1">
                <label class="col-md-3 offset-md-2" for="username">用户名:</label>
                <input class="col-md-5" type="text" name="username" id="username" >
                <span></span>
            </li>
            <li class="row p-1">
                <label class="col-md-3 offset-md-2" for="password">密码:</label>
                <input class="col-md-5" type="password" name="password" id="password">
                <span></span>
            </li>
            <li class="row p-1">
                <label class="col-md-3 offset-md-2" for="cpassword">确认密码:</label>
                <input class="col-md-5" type="password" name="cpassowrd" id="cpassword">
                <span></span>
            </li>
            <li class="row p-1">
                <label class="col-md-3 offset-md-2" for="phone">联系方式:</label>
                <input class="col-md-5" type="text" name="phone" id="phone">
                <span></span>
            </li>
        </ul>
    </div>


    <div class="row mx-auto">
        <div class="mx-auto">
            <button id="btn-register" type="button" class="btn btn-dark w-25 mb-4 mx-4" data-href='/adminInsertUser'>
                添加
            </button>
        </div>
    </div>
</form>

</body>
<script>
    $(document).ready(function(){

        $("#username").blur(function (){
            $.ajax({
               url: '/checkUserExists?username='+$("#username").val(),
                async: false,
                error: function(){
                   alert('AJAX请求失败')
                },
                success: function(res){
                   if(res == "false")
                       $("#username").next().html("用户名已存在!")
                   else
                       $("#username").next().html('用户名可用!')
                }
            });
        })
        $("#btn-register").click(function (){
            var hf = $(this).data('href')
            $.ajax({
                url: hf,
                type: 'GET',
                data: $("#form-insert-user").serialize(),
                async: false,
                error: function (){
                    alert('AJAX请求错误')
                },
                success: function (res){
                    if (res == "true")
                        alert('添加成功!')
                    else
                        alert('添加失败.')
                    window.location.href='card_admin_insert_user.jsp'
                }
            })
        });
    });
</script>
</html>
